package com.unsins.core.utils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @author odpsoft
 */
public class WebUtils {

	private WebUtils() {
	}

	/**
	 * 重载Spring WebUtils中的函数,作用如函数名所示 加入泛型转换,改变输入参数为request 而不是session
	 * 
	 * @param name
	 *            session中变量名称
	 * @param clazz
	 *            session中变量的类型
	 */
	public static Object getOrCreateSessionAttribute(final HttpServletRequest request, String name, Class clazz) {
		return org.springframework.web.util.WebUtils.getOrCreateSessionAttribute(request.getSession(), name, clazz);
	}

	public static Object getSessionAttribute(final HttpServletRequest request, String name) {
		return org.springframework.web.util.WebUtils.getSessionAttribute(request, name);
	}

	public static void createSessionAttribute(final HttpServletRequest request, String name, Object value) {
		org.springframework.web.util.WebUtils.setSessionAttribute(request, name, value);
	}

	public static void removeSessionAttribute(final HttpServletRequest request, String name) {
		HttpSession session = request.getSession();
		session.removeAttribute(name);
		session.invalidate();
	}
}
